package com.liuxin.mycontactdemo.provider;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;


import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;

import static org.junit.Assert.*;

public class ContactProviderTest {
    Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    @Test
    public void query() {
        Cursor cursor=appContext.getContentResolver().query(ContactProvider.URI_CONTACT,null,null,null,null);
        int columnCount=cursor.getColumnCount();
        while (cursor.moveToNext())
        {
            for (int i=0;i<columnCount;i++)
            {
                System.out.print(cursor.getString(i)+" ");
            }
            System.out.println("");
        }
    }

    @Test
    public void insert() {
        ContentValues cv=new ContentValues();
        cv.put("name","tom");
        cv.put("phone","12345465");
        cv.put("email","45412@qq.com");
        cv.put("qq","4653213");
        appContext.getContentResolver().insert(ContactProvider.URI_CONTACT,cv);

    }

    @Test
    public void update() {
        ContentValues cv=new ContentValues();
        cv.put("name","liuxin");
        cv.put("phone","18571504459");
        cv.put("email","825848883@qq.com");
        cv.put("qq","825848883");
        appContext.getContentResolver().update(ContactProvider.URI_CONTACT,cv,"name=?",new String[]{"liuxin"});
    }
}